<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="P/O">
              <a-input placeholder="请输入P/O" v-model="queryParam.orderNum"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="发票号">
              <a-input placeholder="请输入发票号" v-model="queryParam.invoiceNum"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item label="入库日期">
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust"
                  v-model="queryParam.inOrderDate_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust"
                  v-model="queryParam.inOrderDate_end"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="到货方式">
                <j-dict-select-tag placeholder="请选择到货方式" v-model="queryParam.sourceOfGoods" dictCode="source_of_goods" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="集装箱号">
                <a-input placeholder="请输入集装箱号" v-model="queryParam.containerNo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="入库类型">
                <j-dict-select-tag placeholder="请选择入库类型" v-model="queryParam.inOrderType" dictCode="in_order_type" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="入库状态">
                <j-dict-select-tag placeholder="请选择入库状态" v-model="queryParam.inOrderType" dictCode="order_status" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否挂起">
                <j-dict-select-tag placeholder="请选择是否挂起" v-model="queryParam.isHangUp" dictCode="is_hang_up" />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('入库单')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
        @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal"
        @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" bordered rowKey="id" class="j-table-force-nowrap" :scroll="{ x: true }"
        :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="isHangUp" slot-scope="text, record">
          <a-switch checked-children="是" un-checked-children="否" @change="onIsHangUp(text, record)"
            :checked="record.isHangUp == 1" />
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item v-if="record.isHangUp === 1 && [1, 2, 3].includes(record.inOrderStatus)">
                <!-- <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm> -->
                <a @click="abend(record)">异常终止</a>
              </a-menu-item>
              <a-menu-item v-if="record.inOrderType >= 3">
                <a @click="getQRCodes(record)">下载二维码</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <in-order1-modal ref="modalForm" @ok="modalFormOk" />
  </a-card>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import InOrder1Modal from './modules/InOrder1Modal'
import { downloadFile } from '@/api/manage'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import '@/assets/less/TableExpand.less'
import { getAction, postAction, putAction } from '@/api/manage'
import store from '@/store'

export default {
  name: "InOrder1List",
  mixins: [JeecgListMixin],
  components: {
    InOrder1Modal
  },
  data() {
    return {
      description: '入库单管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: 'P/O',
          align: "center",
          dataIndex: 'orderNum'
        },
        {
          title: '发票号',
          align: "center",
          dataIndex: 'invoiceNum'
        },
        // {
        //   title: '出货地址',
        //   align: "center",
        //   dataIndex: 'shippingAddress'
        // },
        {
          title: '批次号',
          align: "center",
          dataIndex: 'batchNumber'
        },
        {
          title: '入库日期',
          align: "center",
          dataIndex: 'inOrderDate'
        },
        {
          title: '到货方式',
          align: "center",
          dataIndex: 'sourceOfGoods_dictText'
        },
        // {
        //   title: '集装箱号',
        //   align: "center",
        //   dataIndex: 'containerNo'
        // },
        // {
        //   title: '铅封号',
        //   align: "center",
        //   dataIndex: 'sealNum'
        // },
        // {
        //   title: '国别',
        //   align: "center",
        //   dataIndex: 'nationality'
        // },
        // {
        //   title: '司机姓名',
        //   align: "center",
        //   dataIndex: 'driverName'
        // },
        // {
        //   title: '车牌号',
        //   align: "center",
        //   dataIndex: 'busNum'
        // },
        {
          title: '货品种类',
          align: "center",
          dataIndex: 'skuType_dictText'
        },
        {
            title:'客户编码',
            align:"center",
            dataIndex: 'customerCode'
        },
        {
          title: '总托数',
          align: "center",
          dataIndex: 'trayNum'
        },
        {
          title: '总箱数',
          align: "center",
          dataIndex: 'boxNum'
        },
        {
          title: '总数量',
          align: "center",
          dataIndex: 'pcsNum'
        },
        {
          title: '入库类型',
          align: "center",
          dataIndex: 'inOrderType_dictText'
        },
        {
          title: '入库状态',
          align: "center",
          dataIndex: 'inOrderStatus_dictText'
        },
        {
          title: '优先级',
          align: "center",
          dataIndex: 'priority'
        },
        {
          title: '是否挂起',
          align: "center",
          dataIndex: 'isHangUp',
          scopedSlots: { customRender: 'isHangUp' }
        },
        // {
        //   title: '挂起人',
        //   align: "center",
        //   dataIndex: 'hangUpMan'
        // },
        // {
        //   title: '挂起时间',
        //   align: "center",
        //   dataIndex: 'hangUpTime'
        // },
        // {
        //   title: '解挂人',
        //   align: "center",
        //   dataIndex: 'hangSoluMan'
        // },
        // {
        //   title: '解挂时间',
        //   align: "center",
        //   dataIndex: 'hangSoluTime'
        // },
        // {
        //   title: '理货员',
        //   align: "center",
        //   dataIndex: 'tallyClerk'
        // },
        // {
        //   title: '理货时间',
        //   align: "center",
        //   dataIndex: 'tallyClerkTime'
        // },
        // {
        //   title: '叉车司机',
        //   align: "center",
        //   dataIndex: 'truckDriver'
        // },
        // {
        //   title: '上架时间',
        //   align: "center",
        //   dataIndex: 'truckTime'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' },
        }
      ],
      isorter: {
        column: 'createTime',
        order: 'desc'
      },
      url: {
        list: "/inOrder1/inOrder1/list",
        delete: "/inOrder1/inOrder1/delete",
        deleteBatch: "/inOrder1/inOrder1/deleteBatch",
        exportXlsUrl: "/inOrder1/inOrder1/exportXls",
        importExcelUrl: "inOrder1/inOrder1/importExcel",
        edit: "/inOrder1/inOrder1/edit",
        getQRCodes: "inOrder1/inOrder1/getQRCodes",
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    //下载二维码
    getQRCodes(record) {
      return downloadFile(this.url.getQRCodes, new Date().getTime() + '.zip', { id: record.id } )
    },
    // 异常终止
    abend(record) {
      record.inOrderStatus = 13;
      putAction(this.url.edit, record).then((res) => {
        if (res.success) {
          this.searchQuery();
        }else{
          this.$message.warning(res.message);
          this.searchQuery();
        }
      }).catch((error) => {
        console.log(error);
      })
    },
    // 是否挂起
    onIsHangUp(text, record) {
      let username = store.getters.userInfo.username;
      let date = Date.now();
      //取反
      let a = text == 1 ? 0 : 1;
      //页面设置数据
      record.isHangUp = a;
      if (a == 1) {
        record.hangUpMan = username;
        record.hangUpTime = date;
      } else {
        record.hangSoluMan = username;
        record.hangSoluTime = date;
      }
      // 后端更新数据
      putAction(this.url.edit, record).then((res) => {
        if (res.success) {
          this.searchQuery();
        }else{
          this.$message.warning(res.message);
          this.searchQuery();
        }
      }).catch((error) => {
        console.log(error);
      })
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'orderNum', text: 'P/O', dictCode: '' })
      fieldList.push({ type: 'string', value: 'invoiceNum', text: '发票号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'shippingAddress', text: '出货地址', dictCode: '' })
      fieldList.push({ type: 'string', value: 'batchNumber', text: '批次号', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'inOrderDate', text: '入库日期' })
      fieldList.push({ type: 'int', value: 'sourceOfGoods', text: '到货方式', dictCode: '' })
      fieldList.push({ type: 'string', value: 'containerNo', text: '集装箱号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sealNum', text: '铅封号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'nationality', text: '国别', dictCode: '' })
      fieldList.push({ type: 'string', value: 'driverName', text: '司机姓名', dictCode: '' })
      fieldList.push({ type: 'string', value: 'busNum', text: '车牌号', dictCode: '' })
      fieldList.push({ type: 'int', value: 'skuType', text: '货品种类', dictCode: '' })
      fieldList.push({type:'string',value:'customerCode',text:'客户编码',dictCode:''})
      fieldList.push({ type: 'int', value: 'trayNum', text: '总托数', dictCode: '' })
      fieldList.push({ type: 'int', value: 'boxNum', text: '总箱数', dictCode: '' })
      fieldList.push({ type: 'int', value: 'pcsNum', text: '总数量', dictCode: '' })
      fieldList.push({ type: 'int', value: 'inOrderType', text: '入库类型', dictCode: '' })
      fieldList.push({ type: 'int', value: 'inOrderStatus', text: '入库状态', dictCode: '' })
      fieldList.push({ type: 'int', value: 'isHangUp', text: '是否挂起' })
      fieldList.push({ type: 'int', value: 'priority', text: '优先级' })
      fieldList.push({ type: 'string', value: 'hangUpMan', text: '挂起人', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'hangUpTime', text: '挂起时间' })
      fieldList.push({ type: 'string', value: 'hangSoluMan', text: '解挂人', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'hangSoluTime', text: '解挂时间' })
      fieldList.push({ type: 'string', value: 'tallyClerk', text: '理货员', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'tallyClerkTime', text: '理货时间' })
      fieldList.push({ type: 'string', value: 'truckDriver', text: '叉车司机', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'truckTime', text: '上架时间' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>